package ru.inse.core.dao.realty.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import ru.inse.core.dao.AbstractDao;
import ru.inse.core.dao.DaoException;
import ru.inse.core.dao.realty.IRealtyItemDao;
import ru.inse.core.domain.realty.RealtyItem;

@Repository
public class RealtyItemDao
    extends AbstractDao<RealtyItem>
    implements IRealtyItemDao
{
    
    private static final RealtyItemMapper REALTY_ITEM_MAPPER = new RealtyItemMapper();

    @Transactional(readOnly = true)
    public RealtyItem getById(Long id)
    {
        return getJdbcTemplate().queryForObject("select * from realty_item where id = ?", REALTY_ITEM_MAPPER,
            new Object[]
            {
                id
            });
    }

    @Override
    public void save(RealtyItem entity)
        throws DaoException
    {
        throw new DaoException(DaoException.IDS_METHOD_IS_NOT_IMPLEMENTED);
    }

    @Override
    public void persist(RealtyItem entity)
        throws DaoException
    {
        throw new DaoException(DaoException.IDS_METHOD_IS_NOT_IMPLEMENTED);
    }

    @Override
    public List<RealtyItem> getAll()
    {
        return getJdbcTemplate().query("select * from realty_item", REALTY_ITEM_MAPPER);
    }
    
    @Override
    public String getTableName()
    {
        return "realty_item";
    }
}
